package com.blockchain.front.servlets;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.framework.http.session.Session;
import com.blockchain.framework.http.session.SessionManager;
import com.blockchain.framework.http.session.authentication.PasswordAuthentication;
import com.blockchain.framework.service.ServiceSession;

public class Login extends AbstractFrontServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected boolean mustAuthenticated() {
		return false;
	}

	@Override
	protected void processPost(HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		PasswordAuthentication authentication = new PasswordAuthentication();
		authentication.setAccountName(request.getParameter("username"));
		authentication.setPassword(request.getParameter("password"));
		PrintWriter out=response.getWriter();
		authentication.setVerifyCode(request.getParameter("verifyCode"));
		authentication.setVerifyCodeType("LOGIN");
		try {
			Session session = getResourceProvider().getResource(
					SessionManager.class).getSession(request, response, true);
			session.checkIn(request, response, authentication);
			out.write("1");
		} catch (Throwable e) {
			out.write(e.getMessage());
		}
	}

}
